package com.woniuxy.mapper;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @author 作者
 * @create 2025-06-18 14:21
 */
public class MyBatisUtil {

    static SqlSessionFactory sqlSessionFactory ;

    public static SqlSession getSqlSession(){
        try {
            if (sqlSessionFactory==null) {
                InputStream inputStream =
                        Resources.getResourceAsStream("mybatis-config.xml");
                sqlSessionFactory =
                        new SqlSessionFactoryBuilder().build(inputStream);
            }
            return   sqlSessionFactory.openSession();
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
